Skip to content

Expose iOS MultiFactorResolver to FirebaseAuthMultiFactorException #727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 19, 2025

Conversation

RaphaelHx
Copy link
Contributor

When a user has been enrolled into multifactor, on sign in, a FirebaseAuthMultiFactorException is thrown, and should contain a MultiFactorResolver. This has a function resolveSignIn to handle entering the code.

On Android for example, the exception contains the resolver, and can be extracted and used successfully.

import com.google.firebase.auth.FirebaseAuthMultiFactorException
import dev.gitlive.firebase.auth.MultiFactorResolver

actual fun extractMultiFactorResolver(e: FirebaseAuthMultiFactorException): MultiFactorResolver? {
    return MultiFactorResolver(e.resolver)
}

https://firebase.google.com/docs/auth/android/totp-mfa#sign_in_users_with_a_second_factor

However, on iOS, the resolver isn't included in the exception, and so the code below wouldn't work.

import dev.gitlive.firebase.auth.FirebaseAuthMultiFactorException
import dev.gitlive.firebase.auth.MultiFactorResolver
import kotlinx.cinterop.ExperimentalForeignApi

@OptIn(ExperimentalForeignApi::class)
actual fun extractMultiFactorResolver(e: FirebaseAuthMultiFactorException): MultiFactorResolver? {
    val resolver = e.resolver ?: return null
    return MultiFactorResolver(resolver)
}

https://firebase.google.com/docs/auth/ios/totp-mfa#sign_in_users_with_a_second_factor

This is because NSError.toException() function throws a new error without exposing the required resolver.

17087L, // AuthErrorCode.secondFactorAlreadyEnrolled
17078L, // AuthErrorCode.secondFactorRequired
17088L, // AuthErrorCode.maximumSecondFactorCountExceeded
17084L, // AuthErrorCode.multiFactorInfoNotFound
-> FirebaseAuthMultiFactorException(toString())

Adding the resolver in the exception allows iOS to complete sign in for users with multi factor enrolled.

@RaphaelHx
Copy link
Contributor Author

Fixes #727

}

17052L, // AuthErrorCode.quotaExceeded
-> FirebaseTooManyRequestsException(toString())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matches the behaviour of android

@RaphaelHx
Copy link
Contributor Author

@nbransby @Daeda88 tagging to put this on your radar, thank you.

@nbransby nbransby merged commit 56f3dab into GitLiveApp:master Aug 19, 2025
96 of 97 checks passed
@RaphaelHx
Copy link
Contributor Author

Thank you @nbransby. Any plans to release soon?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants